//
//  QTScanWebViewController.m
//  qdqts
//
//  Created by centling on 14-7-24.
//  Copyright (c) 2014年 seas.cheng. All rights reserved.
//

#import "QTScanWebViewController.h"

@interface QTScanWebViewController ()

@end

@implementation QTScanWebViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title=@"详情";
    // Do any additional setup after loading the view from its nib.
    NSURL *url =[NSURL URLWithString:[self convertPicURL:self.barCode]];
    NSURLRequest*request =[NSURLRequest requestWithURL:url];
    [self.vue loadRequest:request];
    self.vue.delegate=self;
    self.vue.scalesPageToFit = YES;
    [self.indicator startAnimating];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)webViewDidFinishLoad:(UIWebView*)webView{
    [self.indicator stopAnimating];
    NSLog(@"teststetstt");
}


- (void)webViewDidStartLoad:(UIWebView *)webView{
    NSLog(@"teststetstt  did start load");
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    NSLog(@"teststetstt  did fail load");
    [self.indicator stopAnimating];
    
    
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示"
                                                  message:[NSString stringWithFormat:@"网络地址不可达，或无效二维码！",nil]
                                                 delegate:self
                                        cancelButtonTitle:@"确定"
                                        otherButtonTitles:nil, nil];
    
    [alert show];
    
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self.navigationController popViewControllerAnimated:YES];
    
}


-(NSString *)convertPicURL:(NSString *)url
{
    NSString *picURL=url;
    NSRange range_http = [url rangeOfString:@"http:"];
    NSRange range_HTTP = [url rangeOfString:@"HTTP:"];
    if ((range_http.length==0)&&(range_HTTP.length==0)) {
        picURL=[@"http://" stringByAppendingString:url==nil?@"":url];
    }
    return  picURL;
}

@end
